/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Dec 18, 2012  11:14:08 AM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.std.batch.common
 * File Name : projectBatch.java
 * TODO
 */
package com.tis.std.batch.common;

import java.util.List;

import org.apache.log4j.Logger;

import promis.utility.CommonService;
import promis.utility.QueueProcessAction;

import apps.sessionFactory;

import com.tis.std.commons;

/**
 * @author chatree
 *
 */
public class ProjectBatch extends commons {
	private static final Logger log = Logger.getLogger(ProjectBatch.class);
	
	private void BatchExec() throws Exception {
		try{
			
			StringBuilder _strQuery = new StringBuilder();
			_strQuery.append(" SELECT  	COMPANY, PROJECT, PROJECT_NAME, STATUS, SYNC_ISSTAGING, CREATED_BY, CREATED_ON, LAST_UPD_BY, LAST_UPD_ON   ");
			_strQuery.append(" FROM 	SPL.VW_SYNC_BL_COMM_PROJECT ");
			
			List<Object[]> result = (List<Object[]>) sessionFactory.CreateEmPromis().createNativeQuery(_strQuery.toString()).getResultList();
			System.out.println("result size =" + CommonService.getSize(result));
			
			if(!CommonService.IsNull(result)){
				try{
					for (Object[] value : result) {	
						CleanValue();						
						setCompany(CommonService.IsNullRNull(value[0]));
						setProject(CommonService.IsNullRNull(value[1]));						
						setStatus(CommonService.IsNullRNull(value[3]));						
						setSyncIsstaging(CommonService.IsNullRNull(value[4]));
						setProcessAction(QueueProcessAction.BATCH);
						setProcessActionBy(CommonService.IsNullRNull(value[7]));
						setAction(promis.utility.InterfaceAction.project.PER_PROJECT.toString());
						
						new apps.promis.out.common.SyncQueueAction().PutQueue(	promis.utility.BusinessModule.COMMONS.toString(), 
																				promis.utility.ProcessModule.PROJECT.toString(),																				null,
																				QueueProcessAction.BATCH,
																				ConvertParamToHashMap()
																				);
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}catch(Exception e){
			log.error(e.getMessage());
			throw e;
		}
	}
	
	public static void main(String[] args) {
		try{
			
			new ProjectBatch().BatchExec();
			
		}catch(Exception e){
			log.error(e.getMessage());
		}
	}

}
